package com.spark.common.widget

import android.app.Dialog
import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.support.annotation.StyleRes
import android.view.LayoutInflater
import android.widget.TextView
import com.spark.common.R
import io.reactivex.annotations.NonNull

class ErrorAlert(@NonNull context: Context, @StyleRes themeResId: Int) : Dialog(context, themeResId) {
    private constructor(@NonNull context: Context) : this(context, R.style.ConfirmDialogStyle)
    var tvTitle: TextView
    var tvMessage: TextView

    init {
        val rootView = LayoutInflater.from(context).inflate(R.layout.layout_error, null)
        setContentView(rootView)
        setCancelable(true)
        setCanceledOnTouchOutside(true)
        window.setBackgroundDrawable(ColorDrawable())
        tvTitle = rootView.findViewById(R.id.tv_error_title)
        tvMessage = rootView.findViewById(R.id.tv_error_msg)
    }

    fun show(title: String = "", message: String = "") {
        tvTitle.text = title
        tvMessage.text = message
        show()
    }
}